$.fn.getColumn = function (options, callback) {
	//var thisUrl = site.apiUrl + '/menu/selectMenuAll';
	var obj = $(this),
		h = "",
		defaults = {
			type: "column",
			id: ""
		};
	var opts = $.extend({}, defaults, options);
	var name = obj.attr('name') ? obj.attr('name') : '',
		tip = obj.attr('data-tip') ? obj.attr('data-tip') : '',
		valid = obj.attr('data-valid') ? obj.attr('data-valid') : '',
		placeholder = obj.attr('placeholder') ? obj.attr('placeholder') : '',
		error = obj.attr('data-error') ? obj.attr('data-error') : '';
	obj.html("");
	requestPost(options.thisUrl,{}, function (d) {
		var e = d.result;
			edata = [],
			newArr = [];
		$.each(e, function(i, j) {
			edata.push(j);
			newArr.push(j);
		});
		h = '<div class="bbox" style="position:relative;width:100%;">' +
			'<div class="ipt dm sbox" style="position:relative;display:block;width:100%;max-width:100%;min-width:100%;margin:0;">' +
			'<span class="mm zhankai"></span>' +
			'<nobr>' +
			'<input class="chooseData lmtype" name="' + name + '" data-tip="' + tip + '" data-valid="' + valid + '" placeholder="' + placeholder + '" data-error="' + error + '" type="text" style="width:100%;height:24px;padding:10px 0;cursor:default;" readonly name="' + opts.asName + '" />' +
			'</nobr>' +
			'</div>' +
			'<div class="treeBox opennn" style="position:absolute;margin-top: 1px;width:100%;height: 300px;border: 1px #ccc solid;border-radius: 2px;z-index: 999;background-color: #f6f9fe;">' +
			'<div style="height:34px;line-height:34px;padding:0 8px;font-size:14px;border-bottom:1px solid #d4dce5;background-color:#fff;">' +
			'<input class="searchLanM" type="text" style="width:91%;height:90%;" placeholder="请输入菜单名称" /><i class="iconfont icon-search pointer"></i>' +
			'</div>' +
			'<div class="orgTree" style="width:100%;height:88%;padding-left:18px;">' +
			'<div data-id="" class="folder open root active" data-columnCode="">' + 
            '<span class="node"></span><i></i>根目录</div>' +
            '<div class="sonBox child"></div>'
			'</div>' +
			'</div>' +
			'</div>';
		obj.append(h);
		var $contentBox = obj.find('.orgTree');
    	var $addBox = obj.find('.sonBox');
    	var circulationTree = function(data) {
        	var j = data[0];
        	if(j==null|| j == ''){
        		return false;
        	}
        	var $parent = $addBox.find('.children_' + j.parentId);
        	var goAppend = function($box) {
            	$box.append('' +
                    '<div class="thisCol_' + j.id  + ' parent" data-id="' + j.id + '" data-columnCode="' + j.menuCode + '"data-columnclientType="'+j.clientType+'">' + 
                    '<span class="node"></span><i></i>' + j.menuName +
                    '</div>' + 
                    '<div class="children_' + j.id + ' child"></div>').children(':last-child').data('info', j);
            	data.splice(0, 1);
        	}
        	if (j.parentId && $parent.length > 0) {
            	goAppend($parent);
       		} else {
            	goAppend($addBox);
        	};
        	if (data.length > 0) {
            	circulationTree(data);
        	};
        	var treeList = $addBox.find('div.parent');
    		$.each(treeList, function(i, j) {
    			$(this).next('div.child').find('div.parent').length > 0 ? $(this).addClass('folder') : $(this).addClass('file');
    		});
    	};
    	circulationTree(edata);
    	var stopBubble = function(e) {
        	if (e && e.stopPropagation) {      　　
            	e.stopPropagation();
        	} else {
            	window.event.cancelBubble = true;
            	return false;
        	}
    	};
    	$addBox.on("click", 'div', function(event) {
    		stopBubble(event);
        	var tagName = event.target.tagName,
        		$_this = tagName == 'DIV' ? $(event.target) : $(event.target).parent(),
        		open = $_this.hasClass('open'),
        		info = $(this).data('info'),
    			$thisInput = $(this).parents('.bbox').find('.chooseData'),
    			thisName = $_this.text(),
    			thisId = $_this.attr('data-id'),
    			thisCode = $_this.attr('data-columnCode');
    			thisClientType =$_this.attr('data-columnclientType');
        	if (tagName == 'SPAN') {
        		if (!open) {
            		$_this.addClass('open');
        		} else {
            		$_this.removeClass('open');
        		}
        	} else {
        		$contentBox.find('div').removeClass('active');
    			$_this.addClass('active');
    			$thisInput.val(thisName);
    			$thisInput.attr('data-id', thisId);
    			$thisInput.attr('data-columnCode', thisCode);
    			$thisInput.attr('data-columnclientType', thisClientType);
    			$thisInput.blur();
    			obj.val(thisId);
    			obj.find('.treeBox').addClass('opennn');
    			if (typeof (callback) == "function") {
    				var thisData = {
    					id: thisId,
    					code: thisCode,
    					name: thisName,
    					clientType:thisClientType
    				}
					callback(thisData);
				}
        	}
    	});

    	$contentBox.on("click", '.root', function(event) {
    		stopBubble(event);
        	var tagName = event.target.tagName,
            	$_this = tagName == 'DIV' ? $(event.target) : $(event.target).parent(),
    			$thisInput = $(this).parents('.bbox').find('.chooseData'),
    			thisName = $_this.text(),
    			thisId = $_this.attr('data-id'),
    			thisCode = $_this.attr('data-columnCode');
    			thisClientType = $_this.attr('data-columnclientType');
    		$contentBox.find('div').removeClass('active');
    		$_this.addClass('active');
    		$thisInput.val('');
    		$thisInput.attr('data-id', '');
    		$thisInput.attr('data-columnCode', '');
    		$thisInput.blur();
    		obj.find('.treeBox').addClass('opennn');
    		if (typeof (callback) == "function") {
    			var thisData = {
    				id: thisId,
    				code: thisCode,
    				name: thisName,
    				clientType:thisClientType
    			}
				callback(thisData);
			}
    	});
    	obj.find('span.zhankai.mm').on('click', function(event) {
    		var $that = $(event.target),
    		$thisTree = $that.parent('.sbox').next('.treeBox'),
    			showO = $thisTree.hasClass('opennn');
    			showO ? $thisTree.removeClass('opennn') : $thisTree.addClass('opennn');
    	});
    	$contentBox.on('click', 'span.node', function(event) {
        	stopBubble(event);
        	var tagName = event.target.tagName,
            $_this = tagName == 'DIV' ? $(event.target) : $(event.target).parent(),
            open = $_this.hasClass('open');
        	if (!open) {
            	$_this.addClass('open');
        	} else {
            	$_this.removeClass('open');
        	}
    	});
    	obj.find('.searchLanM').on('keyup', function() {
    		var thisKeyword = $(this).val(),
    			thatVal = '',
    			oldVal = $(this).data('oldVal');
    		$(this).data('oldVal', thisKeyword);
    		if (thisKeyword == oldVal) return;
    		$addBox.html('');
    		if (thisKeyword == '') {
					newData = [];
				$.each(e, function(i, j) {
					newData.push(j);
				});
				circulationTree(newData);
				return;
    		}
    		$.each(newArr, function(i, j) {
    			thatVal = j.columnName.indexOf(thisKeyword);
    			if (thatVal > -1) {
        			$addBox.append('' +
                    '<div class="thisCol_' + j.id  + ' file parent" data-id="' + j.id + '" data-columnCode="' + j.menuCode + '" style="margin-left:-10px;">' + j.menuName +
                    '</div>' + 
                    '<div class="children_' + j.id + ' child"></div>').children(':last-child').data('info', j);
    			};
    		});
    	});
    	$(document).on("click",function(e) { 
    		if($(e.target).closest(".bbox").length == 0) { 
    			obj.find('.treeBox').addClass('opennn'); 
    		} 
    	}); 
    	if (opts.id) {
    		$addBox.find('.thisCol_' + opts.id).click();
    		
    	}
	}, 'POST');
};